package cn.hospital.seviceimpl;

import cn.hospital.dao.UserDepartmentMapper;
import cn.hospital.entity.UserDepartment;
import cn.hospital.service.UserDepartmentServie;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserDepartmentServieImpl implements UserDepartmentServie {
    @Resource
    private UserDepartmentMapper userDepartmentMapper;

    /**
     * 添加设置科室管理员
     * @param userDepartment
     * @return
     */
    @Transactional
    @Override
    public int adddepement(UserDepartment userDepartment) {

        return userDepartmentMapper.adddepement(userDepartment);
    }

    /**
     * 查询科室管理表，所有信息，
     * （每一个科室只有一个负责人这个条件判断没做）
     * @return
     */
    @Override
    @Transactional
    public List<UserDepartment> selectUserDepartment() {
        return userDepartmentMapper.selectUserDepartment();
    }

    /**
     * 跟居科室id查询该科室负责人
     *
     * @param id
     * @return
     */
    @Override
    public UserDepartment selectdepementbyid(Integer id) {
        return userDepartmentMapper.selectdepementbyid(id);
    }

    /**
     * 根据id删除科室管理员信息
     * @param id
     * @return
     */
    @Override
    @Transactional
    public int deldepementbyid(Integer id) {
        return userDepartmentMapper.deldepementbyid(id);
    }

    @Override
    public boolean selectdepementbyksid(Integer ksid) {
        boolean b = false;
        UserDepartment phone =userDepartmentMapper.selectdepementbyksid(ksid);
        if(phone == null) {
            b = true;
        }

        return b;
    }

    @Override
    public int upUserDepartment(UserDepartment userDepartment) {

        int row =userDepartmentMapper.upUserDepartment(userDepartment);
        return row;
    }

}
